]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
messageTray: Add NotificationPolicy.newFromApp()
authorFlorian Müllner <fmuellner@gnome.org>
Tue, 6 Feb 2024 17:48:02 +0000 (18:48 +0100)
committerMarge Bot <marge-bot@gnome.org>
Fri, 9 Feb 2024 11:12:51 +0000 (11:12 +0000)
We have several places where we create an application policy
from an app if possible, and fall back to a generic policy
otherwise.

Make that more convenient by adding a small helper method.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3170>

js/ui/messageTray.js

index d5cdf686e48668f4917c216ff2448537207756dd..abdc0982a2a5fea4a76e85fbd0655adae902f7fc 100644 (file)
@@ -161,6 +161,24 @@ export const NotificationPolicy = GObject.registerClass({
             GObject.ParamFlags.READABLE, false),
     },
 }, class NotificationPolicy extends GObject.Object {
+    /**
+     * Create a new policy for app.
+     *
+     * This will be a NotificationApplicationPolicy for valid apps,
+     * or a NotificationGenericPolicy otherwise.
+     *
+     * @param {Shell.App=} app
+     * @returns {NotificationPolicy}
+     */
+    static newForApp(app) {
+        // fallback to generic policy
+        if (!app?.get_app_info())
+            return new NotificationGenericPolicy();
+
+        const id = app.get_id().replace(/\.desktop$/, '');
+        return new NotificationApplicationPolicy(id);
+    }
+
     // Do nothing for the default policy. These methods are only useful for the
     // GSettings policy.
     store() { }